package lanqiao;

import java.util.Arrays;
import java.util.HashMap;

public class chocolate {
    public static void main(String[] args) {
        int k = 5;
        int[][] arr = {{4,5},{2,4}};
        HashMap<Integer, Integer> hashMap = new HashMap<>();
        int[] salary = new int[arr.length];
        for (int i = 0; i < arr.length ; i++) {
            salary[i] = arr[i][0];
            hashMap.put(arr[i][0],arr[i][1]);
        }
       Arrays.sort(salary);
        int money = 0;
        for (int i = 0; i < salary.length; i++) {
            if (hashMap.get(salary[i])<k){
                k-=hashMap.get(salary[i]);
                money = salary[i]*hashMap.get(salary[i]);
            }else if (k!=0){
                money += salary[i]*k;
            }
        }
        System.out.println(money);
    }
}
